package com.wgts.wgts.mvp.view.activity.goodsinfo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import com.wgts.wgts.R;
import com.wgts.wgts.tools.Tools;

import java.util.ArrayList;
import java.util.List;

public class GoodsAllInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private static final int HEADER = 0x0001;

    private static final int BODY = 0x0002;



    private List<Integer> list;

    private Context context;

    public GoodsAllInfoAdapter(List<Integer> BodyList, String head, Context context) {
        this.list = BodyList;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if(i == HEADER){
            return new GoodsInfoHeaderViewHolder(LayoutInflater.from(context).inflate(R.layout.goods_info_head_view_holder, viewGroup, false));
        }


        return new GoodInfoPictureViewHolder(LayoutInflater.from(context).inflate(R.layout.good_info_picture_view_holder, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if(viewHolder instanceof GoodsInfoHeaderViewHolder){
            ((GoodsInfoHeaderViewHolder) viewHolder).lineaEvaluate.removeAllViews();
            View view = LayoutInflater.from(context).inflate(R.layout.evaluate_view_holder, null);
            ((GoodsInfoHeaderViewHolder) viewHolder).lineaEvaluate.addView(view);
            View view1 = LayoutInflater.from(context).inflate(R.layout.evaluate_view_holder, null);
            ((GoodsInfoHeaderViewHolder) viewHolder).lineaEvaluate.addView(view1);
            View view2 = LayoutInflater.from(context).inflate(R.layout.evaluate_view_holder, null);
            ((GoodsInfoHeaderViewHolder) viewHolder).lineaEvaluate.addView(view2);
        }
        if(viewHolder instanceof GoodInfoPictureViewHolder){
            ((GoodInfoPictureViewHolder) viewHolder).imgPicture.setImageResource(list.get(i - 1));
        }
    }

    @Override
    public int getItemCount() {
        return list.size() + 1;
    }


    @Override
    public int getItemViewType(int position){
        if(position == 0){
            return HEADER;
        }
        return BODY;
    }


    public class GoodsInfoHeaderViewHolder extends RecyclerView.ViewHolder {
        public LinearLayout lineaEvaluate;
        public GoodsInfoHeaderViewHolder(@NonNull View itemView) {

            super(itemView);
            //lineaEvaluate = itemView.findViewById(R.id.linea_evaluate);

        }
    }

    public class GoodInfoPictureViewHolder extends RecyclerView.ViewHolder {

        public ImageView imgPicture;

        public GoodInfoPictureViewHolder(@NonNull View itemView) {
            super(itemView);
            imgPicture = itemView.findViewById(R.id.img_picture);
        }
    }



}
